package org.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.example.entity.AnnualLeave;
import org.example.models.R;
import org.example.service.AnnualLeaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 鸢一折纸
 * @Email: 3498881048@qq.com
 * @Date: 2025/09/04 15:55
 * @Description:
 **/

@RestController
@RequestMapping("/annualLeave")
public class AnnualLeaveController {

    @Autowired
    private AnnualLeaveService annualLeaveService;

    @GetMapping("/page")
    public R<Page<AnnualLeave>> getAllAnnualLeave(
            @RequestParam(name = "current", defaultValue = "1") int current,
            @RequestParam(name = "size", defaultValue = "4") int size,
            @RequestParam(name = "userId", required = false) Integer userId
    ) {
        QueryWrapper<AnnualLeave> query = new QueryWrapper<>();
        query.lambda().eq(AnnualLeave::getUserId, userId);

        query.lambda().orderByDesc(AnnualLeave::getAnnualCycle);

        Page<AnnualLeave> page = new Page<>(current, size);
        annualLeaveService.page(page, query);
        return R.success(page);
    }
}
